/* $Id:background.h $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/

#ifndef __BACKGROUND_H
#define __BACKGROUND_H

#include <string>
#include <map>
#include <list>
using namespace std;

#include "skill.h"

#define loopBackgroundSkills(r,v) loopMap((r)->listSkills(),v,class skill)

class background {
    string name;
    int nr;
    string description;
    map<string,class skill> skills;
public:
    background();

    // Field : name
    const string getName() const;
    void setName(const string v);

    // Field : nr
    const int getNr() const;
    void setNr(const int v);
    int operator<(const class background &ck) const;

    // Field : description
    const string getDescription() const;
    void setDescription(const string v);

    // Field : skills
    class skill& getSkills(const string v);
    map<string,class skill>& listSkills();
    void setSkills(class skill &v);
    void delSkills(const string v);
    const bool isSkills(const string v) const;

    void save(class channel &ch);
    void load(class channel &ch);
    void xml(ofstream &f, int l=0, int r=0);
};

// Repository

#define loopBackgrounds(v) loopSingle(background_repo.listBackground(),v,class background,list)

class backgroundRepository {
    map<string,background> backgrounds;
    int max_nr;
public:
    backgroundRepository();
    class background& getBackground(const string v);
    void setBackground(class background& v);
    list<class background>& listBackground();
    void delBackground(const string v);
    const bool isBackground(const string v) const;
    multimap<string, sigc::signal<void, class background& > > relations;
    bool load(class channel &ch);
    void save(class channel &ch);
};

extern backgroundRepository background_repo;

#endif // __BACKGROUND_H
